TDF2018 Shader Coding Battle
https://gyazo.com/c19794a945058de4c349468102c71737
code:GamTDF.GLSL
// 我無
// - glslfan.com --------------------------------------------------------------
// Ctrl + s or Command + s: compile shader
// Ctrl + m or Command + m: toggle visibility for codepane
// ----------------------------------------------------------------------------
precision mediump float;
uniform vec2 resolution; // resolution (width, height)
uniform vec2 mouse; // mouse (0.0 ~ 1.0)
uniform float time; // time (1second == 1.0)
uniform sampler2D backbuffer; // previous scene
const float PI = 3.1415926;
#define saturate(x) clamp(x, 0.0, 1.0) float dShepre(vec3 p, float r) {
return length(p) - r;
}
vec3 opRep(vec3 p, vec3 c) {
return mod(p, c) - 0.5 * c;
}
vec3 hsv(float h, float s, float v){
vec4 t = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(vec3(h) + t.xyz) * 6.0 - vec3(t.w));
return v * mix(vec3(t.x), clamp(p - vec3(t.x), 0.0, 1.0), s);
}
float dMenger(vec3 z0, vec3 offset, float scale) {
vec4 z = vec4(z0, 1.0);
for (int i = 0; i < 5; i++) {
z = abs(z);
if (z.x < z.y) z.xy = z.yx;
if (z.x < z.z) z.xz = z.zx;
if (z.y < z.z) z.yz = z.zy;
z *= scale;
z.xyz -= offset * (scale - 1.0);
if (z.z < -0.5 * offset.z * (scale - 1.0)) {
z.z += offset.z * (scale - 1.0);
}
}
return length(max(abs(z.xyz) - vec3(1.0), 0.0)) / z.w;
}
mat2 rotate(float a) {
float c = cos(a), s = sin(a);
return mat2(c, s, -s, c);
}
float dScene(vec3 p) {
p -= vec3(1.0);
p = opRep(p, vec3(2.0));
p.xy *= rotate(3.0 * cos(time) * p.z);
float t = 1.0 + sin(time);
t *= 3.0;
float d = dMenger(p, vec3(0.6, 0.9, abs(sin(time))), 2.46);
return d;
}
float dBox(vec2 p, vec2 b) {
vec2 d = abs(p) - b;
return max(d.x, d.y);
}
float dTriangle(vec2 p, vec2 s) {
return dBox(p, vec2(s.x - p.y * s.x / s.y, s.y));
}
float dTDFA(vec2 p) {
vec2 s = vec2(0.1, 0.1);
float d = dTriangle(p, s);
d = min(d, dTriangle((p - vec2(0.25, 0.0)) * vec2(1.0, -1.0), s));
d = min(d, dTriangle((p - vec2(-0.25, 0.0)) * vec2(1.0, -1.0), s));
return d;
}
float dTDFB(vec2 p) {
vec2 s = vec2(0.1, 0.1) * 0.4;
float d = dTriangle((p - vec2(-0.07, 0.0)), s);
d = min(d, dTriangle((p - vec2(0.3, -0.03)) * vec2(0.8, -0.8), s));
return d;
}
void main(){
vec2 uv = (2.0 * gl_FragCoord.xy - resolution) / min(resolution.x, resolution.y);
float beat = time * 128.0 / 60.0;
vec3 c = vec3(uv, 0.0);
float t = beat * 0.5;
vec3 ro = vec3(0.0 * cos(beat), 0.0 * sin(beat), t - 1.0);
vec3 ta = vec3(0.0, 0.0, t);
vec3 fwd = normalize(ta - ro);
vec3 right = cross(fwd, vec3(0, 1, 0));
vec3 up = cross(right, fwd);
vec3 rd = normalize(fwd + uv.x * right + uv.y * up);
float distance = 0.0;
vec3 p = ro;
int step = 0;
for(int i = 0; i < 100; i++) {
step = i;
float d = dScene(p);
distance += d;
p = ro + distance * rd;
if (abs(d) < EPS) break;
}
c = vec3(float(step) * 0.01);
c += hsv(beat * 0.25 + 0.5 * p.z, 1.0, 1.0) * exp(-1.0 * fract(beat));
float fog = 1.0 - exp(-0.05 * pow(distance, 2.0));
c += vec3(0.2, 0.2, 1.0) * fog;
c = mix(c, vec3(0.0), 0.8 * saturate(-1000.0 * dTDFA(uv)));
c += vec3(1.0, 0.1, 0.1) * saturate(0.01 / saturate(dTDFB(uv)));
gl_FragColor = vec4(c, 1.0);
}
code:GamTDF.HLSL
Shader "Unlit/Gam"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
static float PI = 3.1415926;
static float EPS = 1e-4;
static float PI2 = (PI * 2.0);
float3 opRep(float3 p, float3 c) {
//return frac(p / c) - 0.5 * c;
return p - c * trunc(abs(p / c)) - 0.5 * c;
}
float3 hsv(float h, float s, float v) {
float4 t = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
float3 p = abs(frac(float3(h.xxx) + t.xyz) * 6.0 - float3(t.www));
return v * lerp(float3(t.xxx), clamp(p - float3(t.xxx), 0.0, 1.0), s);
}
float dMenger(float3 z0, float3 offset, float scale) {
float4 z = float4(z0, 1.0);
for (int i = 0; i < 5; i++) {
z = abs(z);
if (z.x < z.y) z.xy = z.yx;
if (z.x < z.z) z.xz = z.zx;
if (z.y < z.z) z.yz = z.zy;
z *= scale;
z.xyz -= offset * (scale - 1.0);
if (z.z < -0.5 * offset.z * (scale - 1.0)) {
z.z += offset.z * (scale - 1.0);
}
}
return length(max(abs(z.xyz) - float3(1,1,1), 0.0)) / z.w;
}
float2x2 rotate(float a) {
float c = cos(a), s = sin(a);
return float2x2(c, s, -s, c);
}
float dScene(float3 p) {
//p -= float3(1, 1, 1);
p = opRep(p, float3(1, 1, 1));
p.xy = mul(rotate(3.0 * cos(_Time.y) * p.z), p.xy);
float t = 1.0 + sin(_Time.y);
t *= 3.0;
float d = dMenger(p, float3(0.6, 0.9, abs(sin(_Time.y))), 2.46);
return d;
}
float dBox(float2 p, float2 b) {
float2 d = abs(p) - b;
return max(d.x, d.y);
}
float dTriangle(float2 p, float2 s) {
return dBox(p, float2(s.x - p.y * s.x / s.y, s.y));
}
float dTDFA(float2 p) {
float2 s = float2(0.1, 0.1);
float d = dTriangle(p, s);
d = min(d, dTriangle((p - float2(0.25, 0.0)) * float2(1.0, -1.0), s));
d = min(d, dTriangle((p - float2(-0.25, 0.0)) * float2(1.0, -1.0), s));
return d;
}
float dTDFB(float2 p) {
float2 s = float2(0.1, 0.1) * 0.4;
float d = dTriangle((p - float2(-0.07, 0.0)), s);
d = min(d, dTriangle((p - float2(0.3, -0.03)) * float2(0.8, -0.8), s));
return d;
}
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float2 uv = 2 * i.uv - 1.0;
float beat = _Time.y * 128.0 / 60.0;
float3 c = float3(uv, 0.0);
float t = beat * 0.5;
float3 ro = float3(0.5, 0.5, t - 1.0);
float3 ta = float3(0.5, 0.5, t);
float3 fwd = normalize(ta - ro);
float3 right = cross(fwd, float3(0, 1, 0));
float3 up = cross(right, fwd);
float3 rd = normalize(fwd + uv.x * right + uv.y * up);
float distance = 0.0;
float3 p = ro;
int step = 0;
for (int i = 0; i < 100; i++) {
step = i;
float d = dScene(p);
distance += d;
p = ro + distance * rd;
if (abs(d) < EPS) break;
}
c = (float(step) * 0.01).xxx;
c += hsv(beat * 0.25 + 0.5 * p.z, 1.0, 1.0) * exp(-1.0 * frac(beat));
float fog = 1.0 - exp(-0.05 * pow(distance, 2.0));
c += float3(0.2, 0.2, 1.0) * fog;
c = lerp(c, float3(0,0,0), 0.8 * saturate(-1000.0 * dTDFA(uv)));
c += float3(1.0, 0.1, 0.1) * saturate(0.01 / saturate(dTDFB(uv)));
return float4(c, 1.0);
}
ENDCG
}
}
}
https://gyazo.com/6c4e53bb3465d9ddf45ab1bf696385f2.png
code:FMSTDF.GLSL
// FM Synthesis
precision highp float;
uniform float time;
uniform vec2 resolution;
mat2 rotate2D( float _t ) {
return mat2( cos( _t ), sin( _t ), -sin( _t ), cos( _t ) );
}
float smin( float a, float b, float k ) {
float res = exp( -k * a ) + exp( -k * b );
return -log( res ) / k;
}
struct Camera {
vec3 pos;
vec3 dir;
vec3 sid;
vec3 top;
float fov;
};
struct Ray {
vec3 dir;
vec3 ori;
};
Camera camInit( in vec3 _pos, in vec3 _tar, in float _rot, in float _fov ) {
Camera cam;
cam.pos = _pos;
cam.dir = normalize( _tar - _pos );
cam.sid = normalize( cross( cam.dir, vec3( 0.0, 1.0, 0.0 ) ) );
cam.top = normalize( cross( cam.sid, cam.dir ) );
cam.sid = cos( _rot ) * cam.sid + sin( _rot ) * cam.top;
cam.top = normalize( cross( cam.sid, cam.dir ) );
cam.fov = _fov;
return cam;
}
Ray rayInit( in vec3 _ori, in vec3 _dir ) {
Ray ray;
ray.dir = _dir;
ray.ori = _ori;
return ray;
}
Ray rayFromCam( in vec2 _p, in Camera _cam ) {
vec3 dir = normalize(
_p.x * _cam.sid
+ _p.y * _cam.top
+ _cam.dir / tan( _cam.fov * PI / 360.0 ) // Is this correct?
);
return rayInit( _cam.pos, dir );
}
float distBox( vec3 _p, vec3 _s ) {
vec3 d = abs( _p ) - _s;
return min( max( d.x, max( d.y, d.z ) ), 0.0 ) + length( max( d, 0.0 ) );
}
vec3 typeIfs( vec3 _p, vec3 _rot, vec3 _shift ) {
vec3 pos = _p;
vec3 shift = _shift;
for ( int i = 0; i < 5; i ++ ) {
float intensity = pow( 2.0, -float( i ) );
pos = abs( pos ) - shift * intensity;
shift.yz = rotate2D( _rot.x ) * shift.yz;
shift.zx = rotate2D( _rot.y ) * shift.zx;
shift.xy = rotate2D( _rot.z ) * shift.xy;
if ( pos.x < pos.y ) { pos.xy = pos.yx; }
if ( pos.x < pos.z ) { pos.xz = pos.zx; }
if ( pos.y < pos.z ) { pos.yz = pos.zy; }
}
return pos;
}
float distFunc( vec3 _p ) {
vec3 p = _p;
p.z = ( mod( p.z - 5.0 * time, 2.0 ) - 2.5 );
p.y = mod( p.y, 4.0 ) - 2.0;
p.xyz = p.xzy;
float f = 0.0 + 0.4 * _p.z;
float ff = 1.2 + 0.4 * _p.z;
vec3 p2 = typeIfs(
p,
vec3( 0.01, 0.05, 0.04 ),
vec3( 4.9 + 0.4 * sin( f + time ), 1.1 + 0.1 * sin( f + time / 0.7 ), 2.7 * 0.2 * sin( f + time / 0.8 ) )
);
float dist = distBox( p2, vec3( 0.2 ) );
p2 = typeIfs(
p,
vec3( 0.01, 0.02, 0.03 ),
vec3( 3.1 + 0.4 * sin( ff + time ), 2.1 + 0.1 * sin( ff + time / 0.7 ), 2.7 * 0.2 * sin( ff + time / 0.8 ) )
);
dist = min( dist, distBox( p2, vec3( 0.2 ) ) );
p = _p;
p.zx = rotate2D( time ) * p.zx;
dist = min( dist, distBox( p, vec3( -0.1 * ( p.y - 2.0 ), 1E9, -0.1 * ( p.y - 2.0 ) ) ) );
return dist;
}
vec3 normalFunc( vec3 p, float D ) {
vec2 d = vec2( 0.0, D );
return normalize( vec3(
distFunc( p + d.yxx ) - distFunc( p - d.yxx ),
distFunc( p + d.xyx ) - distFunc( p - d.xyx ),
distFunc( p + d.xxy ) - distFunc( p - d.xxy )
) );
}
void main() {
vec2 uv = gl_FragCoord.xy / resolution;
vec2 p = ( gl_FragCoord.xy * 2.0 - resolution ) / resolution.y;
Camera cam = camInit(
vec3( 0.5 * sin( time ), 0.5 * sin( time / 0.9 ), 5.0 ), // position
vec3( 0.0, 0.0, 0.0 ), // target
0.1 * sin( time / 0.6 ), // roll
50.0 // fov
);
Ray ray = rayFromCam( p, cam );
float rayLen = 0.01;
vec3 rayPos = ray.ori + ray.dir * rayLen;
float dist;
for ( int i = 0; i < MARCH_ITER; i ++ ) {
dist = distFunc( rayPos );
rayLen += MARCH_MUL * dist;
rayPos = ray.ori + ray.dir * rayLen;
}
vec3 col = vec3( 0.0 );
if ( dist < MARCH_EPSILON ) {
vec3 normal = normalFunc( rayPos, 1E-4 );
float edge = smoothstep( 0.1, 0.4, length( normal - normalFunc( rayPos, 2E-2 ) ) );
vec3 ligPos = vec3( 3.0, 4.0, 5.0 );
vec3 ligDir = normalize( cam.pos - ligPos );
col = vec3( 0.4, 0.5, 0.6 ) * ( 0.5 + 0.5 * dot( normal, ligDir ) );
col += vec3( 1.1, 0.3, 0.2 ) * edge;
}
col -= 0.4 * length( p );
col = vec3(
smoothstep( 0.00, 1.00, col.x ),
col.y,
0.1 + 0.8 * col.z
);
col = mix( vec3( 0.8, 1.1, 1.8 ), col, exp( -0.1 * rayLen ) );
gl_FragColor = vec4( col, 1.0 );
}
code:FMSTDF.HLSL
Shader "Unlit/FM Synthesis"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
static float PI = 3.14159265;
static float MARCH_ITER = 100;
static float MARCH_MUL = 0.8;
static float MARCH_EPSILON = 0.01;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float mod(float x, float y)
{
return x - y * floor(x / y);
}
float2x2 rotate2D(float _t) {
return float2x2(cos(_t), sin(_t), -sin(_t), cos(_t));
}
float smin(float a, float b, float k) {
float res = exp(-k * a) + exp(-k * b);
return -log(res) / k;
}
struct Camera {
float3 pos;
float3 dir;
float3 sid;
float3 top;
float fov;
};
struct Ray {
float3 dir;
float3 ori;
};
Camera camInit(in float3 _pos, in float3 _tar, in float _rot, in float _fov) {
Camera cam;
cam.pos = _pos + float3(0, 0, 5);
cam.dir = normalize(_tar - _pos);
cam.sid = normalize(cross(cam.dir, float3(0.0, 1.0, 0.0)));
cam.top = normalize(cross(cam.sid, cam.dir));
cam.sid = cos(_rot) * cam.sid + sin(_rot) * cam.top;
cam.top = normalize(cross(cam.sid, cam.dir));
cam.fov = _fov;
return cam;
}
Ray rayInit(in float3 _ori, in float3 _dir) {
Ray ray;
ray.dir = _dir;
ray.ori = _ori;
return ray;
}
Ray rayFromCam(in float2 _p, in Camera _cam) {
float3 dir = normalize(
_p.x * _cam.sid
+ _p.y * _cam.top
+ _cam.dir / tan(_cam.fov * PI / 360.0) // Is this correct?
);
return rayInit(_cam.pos, dir);
}
float distBox(float3 _p, float3 _s) {
float3 d = abs(_p) - _s;
return min(max(d.x, max(d.y, d.z)), 0.0) + length(max(d, 0.0));
}
float3 typeIfs(float3 _p, float3 _rot, float3 _shift) {
float3 pos = _p;
float3 shift = _shift;
for (int i = 0; i < 5; i++) {
float intensity = pow(2.0, -float(i));
pos = abs(pos) - shift * intensity;
shift.yz = mul(rotate2D(_rot.x), shift.yz);
shift.zx = mul(rotate2D(_rot.y), shift.zx);
shift.xy = mul(rotate2D(_rot.z), shift.xy);
if (pos.x < pos.y) { pos.xy = pos.yx; }
if (pos.x < pos.z) { pos.xz = pos.zx; }
if (pos.y < pos.z) { pos.yz = pos.zy; }
}
return pos;
}
float distFunc(float3 _p) {
float3 p = _p;
p.z = (fmod(p.z - 5.0 * _Time.y, 2.0) - 2.5);
p.y = fmod(p.y, 4.0) - 2.0;
p.xyz = p.xzy;
float f = 0.0 + 0.4 * _p.z;
float ff = 1.2 + 0.4 * _p.z;
float3 p2 = typeIfs(
p,
float3(0.01, 0.05, 0.04),
float3(4.9 + 0.4 * sin(f + _Time.y), 1.1 + 0.1 * sin(f + _Time.y / 0.7), 2.7 * 0.2 * sin(f + _Time.y / 0.8))
);
float dist = distBox(p2, (0.2).xxx);
p2 = typeIfs(
p,
float3(0.01, 0.02, 0.03),
float3(3.1 + 0.4 * sin(ff + _Time.y), 2.1 + 0.1 * sin(ff + _Time.y / 0.7), 2.7 * 0.2 * sin(ff + _Time.y / 0.8))
);
dist = min(dist, distBox(p2, (0.2).xxx));
p = _p;
p.zx = mul(rotate2D(_Time.y) , p.zx);
dist = min(dist, distBox(p, float3(-0.1 * (p.y - 2.0), 1E9, -0.1 * (p.y - 2.0))));
return dist;
}
float3 normalFunc(float3 p, float D) {
float2 d = float2(0.0, D);
return normalize(float3(
distFunc(p + d.yxx) - distFunc(p - d.yxx),
distFunc(p + d.xyx) - distFunc(p - d.xyx),
distFunc(p + d.xxy) - distFunc(p - d.xxy)
));
}
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float2 uv = i.uv;
float2 p = 2.0 * i.uv - 1.0;
Camera cam = camInit(
float3(0.5 * sin(_Time.y), 0.5 * sin(_Time.y / 0.9), 5.0), // position
float3(0.0, 0.0, 0.0), // target
0.1 * sin(_Time.y / 0.6), // roll
50.0 // fov
);
Ray ray = rayFromCam(p, cam);
float rayLen = 0.01;
float3 rayPos = ray.ori + ray.dir * rayLen;
float dist;
for (int i = 0; i < MARCH_ITER; i++) {
dist = distFunc(rayPos);
rayLen += MARCH_MUL * dist;
rayPos = ray.ori + ray.dir * rayLen;
}
float3 col = (0.0).xxx;
if (dist < MARCH_EPSILON) {
float3 normal = normalFunc(rayPos, 1E-4);
float edge = smoothstep(0.1, 0.4, length(normal - normalFunc(rayPos, 2E-2)));
float3 ligPos = float3(3.0, 4.0, 5.0);
float3 ligDir = normalize(cam.pos - ligPos);
col = float3(0.4, 0.5, 0.6) * (0.5 + 0.5 * dot(normal, ligDir));
col += float3(1.1, 0.3, 0.2) * edge;
}
col -= 0.4 * length(p);
col = float3(
smoothstep(0.00, 1.00, col.x),
col.y,
0.1 + 0.8 * col.z
);
col = lerp(float3(0.8, 1.1, 1.8), col, exp(-0.1 * rayLen));
return fixed4(col, 1.0);
}
ENDCG
}
}
}
https://gyazo.com/6c4e53bb3465d9ddf45ab1bf696385f2.png
code:YasaiTDF.GLSL
// 野菜
// - glslfan.com --------------------------------------------------------------
// Ctrl + s or Command + s: compile shader
// Ctrl + m or Command + m: toggle visibility for codepane
// ----------------------------------------------------------------------------
precision mediump float;
uniform vec2 resolution; // resolution (width, height)
uniform vec2 mouse; // mouse (0.0 ~ 1.0)
uniform float time; // time (1second == 1.0)
uniform sampler2D backbuffer; // previous scene
const float PI = 3.1415926;
#define sm(x) (smoothstep(0.25, 0.75, x) vec3 hsv(float h, float s, float v){
vec4 t = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(vec3(h) + t.xyz) * 6.0 - vec3(t.w));
return v * mix(vec3(t.x), clamp(p - vec3(t.x), 0.0, 1.0), s);
}
float map(vec3 p) {
float st = length(mod(p, 2.0) - 1.0) - 0.36;
float t = length(mod(p.xz, 4.0) - 2.0) - 0.1;
//t = max(-t, cos(p.x) + cos(p.z + cos(p.x + time)));
float gr = 8.0 - dot(abs(p), vec3(0.0, 1.0 + sin(p.x) * 0.3 + sin(p.y) * 0.3, 0.0));
t = min(t, length(mod(p.xy, 4.0) - 2.0) - 0.1);
p.x += sin(p.z + tm * 3.0) * 1.0;
p.y += cos(p.z + tm * 3.0) * 1.3;
t = min(t, length(mod(p.zy, 4.0) - 2.0) - 0.05);
t = min(t, length(mod(p.xy, 4.0) - 2.0) - 0.05);
return min(gr, min(st, t));
}
vec2 rot(vec2 p, float t) {
return vec2(
cos(t) * p.x - sin(t) * p.y,
sin(t) * p.x + cos(t) * p.y);
}
void main() {
vec2 uv = (gl_FragCoord.xy / resolution) * 2.0 - 1.0;
vec2 tuv = uv;
uv.x *= resolution.x / resolution.y;
vec3 pos = vec3(0.0, 0.0, time * 1.2);
vec3 dir = normalize(vec3(uv, 1.0));
float t = 0.0;
dir.xy = rot(dir.xy, tm);
dir.yz = rot(dir.yz, tm * 0.5);
for(int i = 0 ; i < 1024; i++) {
float km = map(t * dir + pos) * 0.2;
if(km < 0.01) break;
t += km;
}
vec3 ip = pos + dir * t;
vec3 col = vec3(t * 0.5);
gl_FragColor = vec4(map(ip + 0.1) * vec3(col * 1.0) + dir, 1.0)
* 1.0 - dot(tuv * 0.5, tuv);
gl_FragColor.a = 1.0;
vec3 jn = vec3(0.0);
gl_FragColor.xyz += vec3(0.5);
// uv -= vec2(2.25);
gl_FragColor.xyz *= 1.4;
if(dot(uv, uv) < 0.7) {
gl_FragColor.x = 1.0;
}
gl_FragColor.z += sin(sin(uv.y) + uv.y * 100.0);
//gl_FragColor.x += sin(sin(uv.x) + uv.x * 100.0);
}
code:YasaiTDF.HLSL
Shader "Unlit/Yasai"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType" = "Opaque" }
LOD 100
Pass
{
CGPROGRAM
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
static float PI = 3.1415926;
float mod(float x, float y)
{
return x - y * floor(x / y);
}
float2 mod(float2 x, float2 y)
{
return x - y * floor(x / y);
}
float3 mod(float3 x, float3 y)
{
return x - y * floor(x / y);
}
float3 hsv(float h, float s, float v) {
float4 t = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
float3 p = abs(frac((h).xxx + t.xyz) * 6.0 - t.www);
return v * lerp(float3(t.xxx), clamp(p - float3(t.xxx), 0.0, 1.0), s);
}
float map(float3 p) {
float st = length(mod(p, (2.0).xxx) - 1.0) - 0.36;
float t = length(mod(p.xz, (4.0).xx) - 2.0) - 0.1;
//t = max(-t, cos(p.x) + cos(p.z + cos(p.x + time)));
float gr = 8.0 - dot(abs(p), float3(0.0, 1.0 + sin(p.x) * 0.3 + sin(p.y) * 0.3, 0.0));
t = min(t, length(mod(p.xy, (4.0).xx) - 2.0) - 0.1);
p.x += sin(p.z + _Time.y * 3.0) * 1.0;
p.y += cos(p.z + _Time.y * 3.0) * 1.3;
t = min(t, length(mod(p.zy, (4.0).xx) - 2.0) - 0.05);
t = min(t, length(mod(p.xy, (4.0).xx) - 2.0) - 0.05);
return min(gr, min(st, t));
}
float2 rot(float2 p, float t) {
return float2(
cos(t) * p.x - sin(t) * p.y,
sin(t) * p.x + cos(t) * p.y);
}
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
float4 gl_FragColor = (0).xxxx;
float2 uv = i.uv * 2.0 - 1.0;
float2 tuv = uv;
float3 pos = float3(0.0, 0.0, _Time.y * 1.2);
float3 dir = normalize(float3(uv, 1.0));
float t = 0.0;
dir.xy = rot(dir.xy, _Time.y);
dir.yz = rot(dir.yz, _Time.y * 0.5);
for (int i = 0; i < 1024; i++) {
float km = map(t * dir + pos) * 0.2;
if (km < 0.01) break;
t += km;
}
float3 ip = pos + dir * t;
float3 col = (t * 0.5).xxx;
gl_FragColor = float4(map(ip + 0.1) * float3(col * 1.0) + dir, 1.0)
* 1.0 - dot(tuv * 0.5, tuv);
gl_FragColor.a = 1.0;
float3 jn = (0.0).xxx;
gl_FragColor.xyz += (0.5).xxx;
gl_FragColor.xyz *= (1.4).xxx;
if (dot(uv, uv) < 0.7) {
gl_FragColor.x = 1.0;
}
gl_FragColor.z += sin(sin(uv.y) + uv.y * 100.0);
return gl_FragColor;
}
ENDCG
}
}
}
https://gyazo.com/6c4e53bb3465d9ddf45ab1bf696385f2.png
code:notargsTDF.GLSL
// !args
precision mediump float;
uniform vec2 resolution; // resolution (width, height)
uniform vec2 mouse; // mouse (0.0 ~ 1.0)
uniform float time; // time (1second == 1.0)
uniform sampler2D backbuffer; // previous scene
const float PI = 3.1415926;
vec3 hsv(float h, float s, float v)
{
vec4 t = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(vec3(h) + t.xyz) * 6.0 - vec3(t.w));
return v * mix(vec3(t.x), clamp(p - vec3(t.x), 0.0, 1.0), s);
}
float sdBox( vec3 p, vec3 b )
{
vec3 d = abs(p) - b;
return length(max(d,0.0))
+ min(max(d.x,max(d.y,d.z)),0.0); // remove this line for an only partially signed sdf
}
mat2 rot(float a)
{
return mat2(cos(a), -sin(a), sin(a), cos(a));
}
float dist(vec3 pos)
{
//mat2 r = rot(time * 0.1);
pos = mod(pos, 10.0) - 5.0;
float d = 1000000000000.0;
d = min(sdBox(pos, vec3(2, 4, 2)), d);
//d = min(pos.y - 10.5, d);
return d;
}
vec3 calcNormal(vec3 pos)
{
vec2 ep = vec2(0.001, 0);
return normalize(vec3(
dist(pos) - dist(pos + ep.xyy),
dist(pos) - dist(pos + ep.yxy),
dist(pos) - dist(pos + ep.yyx)
));
}
float rand(vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
void main()
{
vec2 uv = (gl_FragCoord.xy - resolution / 2.0) / resolution.y;
uv.x += rand(vec2(floor(uv.y * 20.0), 0.0)) * pow(1.0 - fract(time), 8.0) * 1.1;
uv.x += rand(vec2(floor(uv.x * 20.0), 0.0)) * pow(1.0 - fract(time + 0.5), 8.0) * 1.1;
vec3 col = vec3(0.0);
//col = 0.01 / abs(length(uv.xy) * vec3(1) - 0.2 + sin(atan(uv.x, uv.y) * 8.0 + time * 4.0) * sin(time * 4.0) * 0.1);
/*
if (abs(mod(uv.x + time * 0.4, 0.1)) - 0.05 < 0.001)
{
col += 0.5 * vec3(0, 0, 1);
}
if (abs(mod(uv.y + time * 0.2, 0.1)) - 0.05 < 0.001)
{
col += 0.5 * vec3(1, 0, 0);
}
*/
vec3 startPos = vec3(0, 0, time * 50.0);
vec3 pos = startPos;
vec3 dir = normalize(vec3(uv, 1));
dir.xy = rot(sin(time) * 0.4) * dir.xy;
dir.xz = rot(sin(time * 0.2) * 0.2) * dir.xz;
float depth = 0.0;
for (int i = 0; i < 128; ++i)
{
float d = dist(pos);
pos += d * dir;
depth = float(i);
if (d < 0.001)
{
if (mod(pos.y, 1.0) < 0.5 && mod(pos.x, 1.0) < 0.8)
{
col = hsv(floor(pos.x) * 0.5 + floor(pos.y) * 0.2 + floor(pos.z) * 0.1 + time, 0.8, rand(floor(pos.xy)));
}
else
{
col = vec3(0.1);
}
break;
}
}
col += depth / 128.0;
gl_FragColor = vec4(col, 1.0);
}
code:notargsTDF.HLSL
Shader "Unlit/notargs"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType" = "Opaque" }
LOD 100
Pass
{
CGPROGRAM
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float mod(float x, float y)
{
return x - y * floor(x / y);
}
float3 mod(float3 x, float3 y)
{
return x - y * floor(x / y);
}
float3 hsv(float h, float s, float v)
{
float4 t = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
float3 p = abs(frac((h).xxx + t.xyz) * 6.0 - (t.www));
return v * lerp(float3(t.xxx), clamp(p - float3(t.xxx), 0.0, 1.0), s);
}
float sdBox(float3 p, float3 b)
{
float3 d = abs(p) - b;
return length(max(d,0.0))
+ min(max(d.x,max(d.y,d.z)),0.0); // remove this line for an only partially signed sdf
}
float2x2 rot(float a)
{
return float2x2(cos(a), -sin(a), sin(a), cos(a));
}
float dist(float3 pos)
{
pos = mod(pos, 10.0) - 5.0;
float d = 1000000000000.0;
d = min(sdBox(pos, float3(2, 4, 2)), d);
return d;
}
float3 calcNormal(float3 pos)
{
float2 ep = float2(0.001, 0);
return normalize(float3(
dist(pos) - dist(pos + ep.xyy),
dist(pos) - dist(pos + ep.yxy),
dist(pos) - dist(pos + ep.yyx)
));
}
float rand(float2 co) {
return frac(sin(dot(co.xy ,float2(12.9898,78.233))) * 43758.5453);
}
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
float2 uv = i.uv - 0.5;
uv.x += rand(float2(floor(uv.y * 20.0), 0.0)) * pow(1.0 - frac(_Time.y), 8.0) * 1.1;
uv.x += rand(float2(floor(uv.x * 20.0), 0.0)) * pow(1.0 - frac(_Time.y + 0.5), 8.0) * 1.1;
float3 col = (0.0).xxx;
//col = 0.01 / abs(length(uv.xy) * float3(1) - 0.2 + sin(atan(uv.x, uv.y) * 8.0 + time * 4.0) * sin(time * 4.0) * 0.1);
/*
if (abs(mod(uv.x + time * 0.4, 0.1)) - 0.05 < 0.001)
{
col += 0.5 * float3(0, 0, 1);
}
if (abs(mod(uv.y + time * 0.2, 0.1)) - 0.05 < 0.001)
{
col += 0.5 * float3(1, 0, 0);
}
*/
float3 startPos = float3(0, 0, _Time.y * 50.0);
float3 pos = startPos;
float3 dir = normalize(float3(uv, 1));
dir.xy = mul(rot(sin(_Time.y) * 0.4) , dir.xy);
dir.xz = mul(rot(sin(_Time.y * 0.2) * 0.2) , dir.xz);
float depth = 0.0;
for (int i = 0; i < 128; ++i)
{
float d = dist(pos);
pos += d * dir;
depth = float(i);
if (d < 0.001)
{
if (mod(pos.y, 1.0) < 0.5 && mod(pos.x, 1.0) < 0.8)
{
col = hsv(floor(pos.x) * 0.5 + floor(pos.y) * 0.2 + floor(pos.z) * 0.1 + _Time.y, 0.8, rand(floor(pos.xy)));
}
else
{
col = (0.1).xxx;
}
break;
}
}
col += depth / 128.0;
return fixed4(col, 1.0);
}
ENDCG
}
}
}